{% extends 'oracle/base.html' %}
{% load static %}
{% load oracle %}

{% block content %}
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox">
                    <div class="ibox-title">
                        <h5>
                            待注册权限列表
                            <small class="m-l-sm">库中不存在的权限一起进行注册！</small>
                        </h5>
                        <div class="ibox-tools">
                            <a class="btn btn-success btn-rounded btn-sm" id="generate_form_submit"
                               style="color: white!important;">
                                <i class="fa fa-superpowers"></i> 批量注册权限
                            </a>
                            {% if request|has_permission:'oracle:menu_list' %}
                                <a class="btn btn-primary btn-rounded btn-sm" href="{% url 'oracle:menu_list' %}">
                                    <i class="fa fa-bolt"></i> 菜单列表
                                </a>
                            {% endif %}
                            {% if request|has_permission:'oracle:menu_link_add' %}
                                <a class="btn btn-primary btn-rounded btn-sm" href="{% url 'oracle:menu_link_add' %}">
                                    <i class="fa fa-cubes"></i> 关联菜单
                                </a>
                            {% endif %}
                            <a class="btn btn-info btn-circle collapse-link" type="button"
                               style="color: white!important;">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <form method="post" action="{% url 'oracle:multi_permission_add' %}" id="generate_form">
                            {% csrf_token %}
                            {{ data.generate_formset.management_form }}
                            <table class="table">
                                <thead>
                                <tr>
                                    <th scope="col">#</th>
                                    <th scope="col">名称</th>
                                    <th scope="col">URL</th>
                                    <th scope="col">别名</th>
                                </tr>
                                </thead>
                                <tbody>
                                {% for form in data.generate_formset %}
                                    <tr>
                                        <td>{{ forloop.counter }}</td>
                                        {% for field in form %}
                                            {% if field.name == 'key' or field.name == 'status' or field.name == 'level' %}
                                                <td class="d-none">{{ field }}<span
                                                        style="color: red">{{ field.errors.0 }}</span></td>
                                            {% else %}
                                                <td>{{ field }}<span style="color: red">{{ field.errors.0 }}</span></td>
                                            {% endif %}
                                        {% endfor %}
                                    </tr>
                                {% endfor %}
                                </tbody>
                            </table>
                        </form>
                    </div>
                </div>
            </div>

            <div class="col-lg-12">
                <div class="ibox ">
                    <div class="ibox-title">
                        <h5>待删除权限列表
                            <small class="m-l-sm">路由不存在的权限进行删除，会将库中的关联关系一起清除！</small>
                        </h5>
                        <div class="ibox-tools">
                            <a class="btn btn-info btn-circle collapse-link" type="button"
                               style="color: white!important;">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <table class="table" id="permission_delete_table">
                            <thead>
                            <tr>
                                <th scope="col">#
                                <th class="d-none" scope="col">索引</th>
                                <th scope="col">名称</th>
                                <th scope="col">URL</th>
                                <th scope="col">别名</th>
                                <th class="d-none" scope="col">状态</th>
                                <th class="d-none" scope="col">权重</th>
                                <th scope="col">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {% for row in data.delete_row_list %}
                                <tr>
                                    <td>{{ forloop.counter }}</td>
                                    <td class="d-none">{{ row.key }}</td>
                                    <td>{{ row.title }}</td>
                                    <td>{{ row.url }}</td>
                                    <td>{{ row.name }}</td>
                                    <td class="d-none">{{ row.status }}</td>
                                    <td class="d-none">{{ row.level }}</td>
                                    <td>
                                        <a class="btn btn-danger btn-rounded btn-outline"
                                           href="{% url 'oracle:multi_permission_delete' %}">
                                            <i class="fa fa-trash-o"></i> 删除记录
                                        </a>
                                    </td>
                                </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

            <div class="col-lg-12">
                <div class="ibox ">
                    <div class="ibox-title">
                        <h5>
                            待更新权限列表
                            <small class="m-l-sm">已存在库中的权限信息！注意：如果提示与数据库中不相同，需手动确认！！！</small>
                        </h5>
                        <div class="ibox-tools">
                            <a class="btn btn-success btn-rounded btn-sm" id="update_form_submit"
                               style="color: white!important;">
                                <i class="fa fa-paper-plane"></i> 批量更新权限
                            </a>
                            {% if request|has_permission:'oracle:menu_link_add' %}
                                <a class="btn btn-primary btn-rounded btn-sm" href="{% url 'oracle:menu_link_add' %}">
                                    <i class="fa fa-link"></i> 关联菜单
                                </a>
                            {% endif %}
                            <a class="btn btn-info btn-circle collapse-link" type="button"
                               style="color: white!important;">
                                <i class="fa fa-chevron-up"></i>
                            </a>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <form method="post" action="{% url 'oracle:multi_permission_add' %}" id="update_form">
                            {% csrf_token %}
                            <input class="d-none" value="update" name="type" type="hidden">
                            {{ data.update_formset.management_form }}
                            <table class="table">
                                <thead>
                                <tr>
                                    <th scope="col">#</th>
                                    <th scope="col" class="d-none">id</th>
                                    <th scope="col" class="d-none">索引</th>
                                    <th scope="col">名称</th>
                                    <th scope="col">URL</th>
                                    <th scope="col">别名</th>
                                    <th scope="col" class="d-none">状态</th>
                                    <th scope="col" class="d-none">权重</th>
                                </tr>
                                </thead>
                                <tbody>
                                {% for form in data.update_formset %}
                                    <tr>
                                        <td>{{ forloop.counter }}</td>
                                        {% for field in form %}
                                            <td
                                                    {% if field.name == 'id' or field.name == 'key' or field.name == 'status' or field.name == 'level' %}
                                                        class="d-none"
                                                    {% endif %}
                                            >
                                                {{ field }}
                                                <span style="color: red">{{ field.errors.0 }}</span>
                                            </td>
                                        {% endfor %}
                                    </tr>
                                {% endfor %}
                                </tbody>
                            </table>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block js %}
    <script src="{% static 'oracle/js/plugins/sweetalert/sweetalert.min.js' %}"></script>
    <script src="{% static 'oracle/js/permissions.js' %}"></script>
{% endblock %}